<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>登录</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="static/css/amazeui.css" />
		<link href="static/css/dlstyle.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />	
	</head>

	<body>

		<div class="login-boxtitle" style="width:100%; height: 100px; ">
			<div class="logoBig">
				<img src="static/images/logo.png" style="margin-left: 0px ; height: 100px;">
			</div>
		</div>

		<div class="login-banner">
			<div class="login-main" >
				<div class="login-banner-bg"><span></span><img src="static/images/big.jpg" /></div>
				<!--//登录注册功能的模块-->
				<div class="login-box" style="margin-top: 20px;" id="container">

					<h3 class="title">登录商城</h3>
					<h5 :style="colorStyle" id="tips">{{tips}}&nbsp;</h5><!--登录提示信息-->
					<div class="clear"></div>

					<div class="login-form"  style="background: none; margin-top: 15px;">
						<form>
							<div class="user-name"  style="margin-top: 20px;">
								<label for="user"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></label>
								<input type="text" v-model="username" placeholder="邮箱/手机/用户名" @keyup="checkInfo">
							</div>
							<div class="user-pass"  style="margin-top: 20px;">
								<label for="password"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></label>
								<input type="password" v-model="password" placeholder="请输入密码" @keyup="checkInfo">
							</div>
						</form>
					</div>

					<div class="login-links" >
						<label for="remember-me"><input id="remember-me" type="checkbox">记住密码</label>
						<a href="#" class="am-fr">忘记密码</a>
						<br />
					</div>
					<div class="am-cf">
						<input type="button" @click="doSubmit" value="登 录" class="am-btn am-btn-primary am-btn-sm">
					</div>
					<div class="am-cf">
						<input type="button" onclick="javascript:window.location.href='register.html'" value="注 册" class="am-btn am-btn-default am-btn-sm">
					</div>
					<div class="partner">
						
					</div>

				</div>
			</div>
		</div>

		<div class="footer ">
			<div class="footer-hd ">

			</div>
			<div class="footer-bd ">
				<p>
					<a href="# ">联系我们</a>
					<a href="# ">网站地图</a>
				</p>
			</div>
		</div>
		
		<script type="text/javascript" src="static/js/jquery-1.9.min.js" ></script>
		<script type="text/javascript" src="static/js/vue.js" ></script>
		<script type="text/javascript" src="static/js/axios.min.js" ></script>
		<script type="text/javascript" src="static/js/cookie_utils.js" ></script>
		<script type="text/javascript" src="static/js/utils.js"></script>
		<script type="text/javascript"  src="static/js/base.js"></script>
		<script type="text/javascript">
			

			
			var vm = new Vue({
				el:"#container",
				data: {
					username:"",
					password:"",
					tips:"",
					colorStyle:"color:red",
					isRight: false,
					returnUrl:null,
					pid:0,
					sid:0,
					num:1,
					
				},
				created:function() {
					
//					this.username = getCookieValue("username");
//					this.password = getCookieValue("password");
					//1、当从商品详情页点击购物车跳转到登录页面时，获取提示信息
					this.tips = getUrlParam("tips");
					console.log(this.tips);
					//2、获取returnURL，pid, sid
					this.returnUrl = getUrlParam("returnUrl");
					this.pid = getUrlParam("pid");
					this.sid = getUrlParam("sid");
					this.num = getUrlParam("num");
					console.log(this.returnUrl);
					console.log(this.pid);
					console.log(this.sid);
				},
				methods: {
					doSubmit:function() {
						//1.登录校验
						if(vm.isRight) {
							var url = baseUrl + "user/login";
							axios.get(url, { //账号密码发送到登录接口
								params: {
									username:vm.username,
									password:vm.password
								}
							}).then((res)=>{
								//res.data返回的才是接口的数据
								var vo = res.data;
								console.log(vo);
								if(vo.code == 10000) {
									setCookieValue("token", vo.msg);//将接收到的token存到cookie中
									//将用户的username和图片路径叶设置戴cookie中去，为了下一步首页面可以展示个人用户名和头像
									setCookieValue("userId", vo.data.userId);
								    setCookieValue("username", vo.data.username);
									setCookieValue("userImg", vo.data.userImg);
									if(this.returnUrl == null) {
										window.location.href = "index.html";
									} else {
										this.returnUrl = this.returnUrl + "?m=" + Math.random();
										if(this.pid != null) {
											this.returnUrl = this.returnUrl + "&pid=" + this.pid;
										} 
										if(this.sid != null) {
											this.returnUrl = this.returnUrl + "&sid=" + this.sid;
										}
										if(this.num != null) {
											this.returnUrl = this.returnUrl + "&num=" + this.num;
										}
										window.location.href = this.returnUrl;
									}
									

								} else {
									vm.tips = vo.msg;
								}
								
								
							});
						} else {
							vm.tips = "请输入账号和密码！";
						}
					}, 
					checkInfo:function() {
						//输入框校验
						if(vm.username == "") {
							vm.tips = "请输入用户名！";
							vm.isRight = false;
						}else if(vm.username.length < 5 || vm.username.length > 20){
							vm.tips = "账号的长度必须为5-20个字符！";
							vm.isRight = false;
						} else {
							//账号正确,校验密码
								//1.登录校验
							if(vm.password == "") {
								vm.tips = "请输入密码！";
							    vm.isRight = false;
							}else if(vm.password.length < 6 || vm.password.length > 16){
								vm.tips = "密码的长度必须为6-16个字符！";
								vm.isRight = false;
							} else {
								vm.tips="";
								vm.isRight = true;
							}
						}
					}
				}
			});
			

		</script>
	</body>

</html>